package controllers;

import java.io.Serializable;
import java.util.ArrayList;

import java.util.List;
import java.util.Locale;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;


@ManagedBean(name = "language")
@SessionScoped
public class LocaleController implements Serializable {

	private static final long serialVersionUID = 1L;
	private Locale locale;

	public LocaleController() {
		locale = Locale.GERMAN;
	}

	/**
	 * @author silaghit
	 */
	public String countryChange(String str) {
		List<Locale> locales = new ArrayList<Locale>();
		Locale localeRO = new Locale("ro");
		Locale localeHU = new Locale("hu");
		locales.add(localeRO);
		locales.add(localeHU);
		locales.add(Locale.ENGLISH);
		locales.add(Locale.GERMAN);
		for (Locale localeVar : locales) {
			if (localeVar.toString().equals(str)) {
				FacesContext.getCurrentInstance().getViewRoot()
						.setLocale(localeVar);
				setLocale(localeVar);
			}
		}

		return "ok";
	}

	public Locale getLocale() {
		return locale;
	}

	public void setLocale(Locale locale) {
		this.locale = locale;
	}
	
	public String getLanguage() {
		return locale.getLanguage();
	}

}